package com.sxjh.controller.pub;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxjh.common.BaseController;
import com.sxjh.common.Result;
import com.sxjh.entity.Department;
import com.sxjh.entity.param.DepartmentListParam;
import com.sxjh.entity.result.DepartmentListResult;
import com.sxjh.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author zixin
 * @since 2021-07-31
 */
@RestController
@Api(tags = "部门")
@RequestMapping("/department")
public class DepartmentController extends BaseController {

  @Autowired
  private DepartmentService departmentService;

  @GetMapping
  @ApiOperation("部门查询列表")
  Result<List<DepartmentListResult>> list(DepartmentListParam param) {
    LambdaQueryWrapper<Department> wrapper = new LambdaQueryWrapper<>();
    if (param.getId() != null) wrapper.eq(Department::getId, param.getId());
    if (StrUtil.isNotEmpty(param.getName())) wrapper.like(Department::getName, param.getName());
    List<Department> list = departmentService.list(wrapper);
    return ok(copyList(list, DepartmentListResult::new));
  }
}

